package com.money.care;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MyOpenHelper extends SQLiteOpenHelper 
{
	// Debug
	final static String TAG = "MyOpenHelper";
	final boolean D = true;
	
	public static final String DB_NAME = "care";
	public static final String TABLE_NAME = "map";
	public static final String ID = "_id";
	public static final String NAME = "name";
	public static final String LATITUDE = "latitude";
	public static final String LONGITUDE = "longitude";
	public static final String ACCURACY = "accuracy";
	public static final String CDATE = "cdate";
	public static final String CTIME = "ctime";
	public static final String CHOUR = "chour";
	public static final String CMIN = "cmin";
	public static final String CSEC = "csec";
	
	public MyOpenHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		Log.w(TAG, "onCreate");
		
		db.execSQL("create table if not exists "+TABLE_NAME+" ("
				+ ID + " integer primary key autoincrement, "
				+ NAME + " varchar, "
				+ LATITUDE + " double, "
				+ LONGITUDE + " double, "
				+ ACCURACY + " integer, "
				+ CDATE + " date default CURRENT_TIMESTAMP, "
				+ CTIME + " time default CURRENT_TIMESTAMP, "
				+ CHOUR + " integer, "
				+ CMIN + " integer, "
				+ CSEC + " integer "
				+ 	") "
				);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		Log.e(TAG, "Drop DB.");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		onCreate(db);
	}

}
